public class House implements Runnable {
    int waterAmount;       //��int����ģ��ˮ��
    Thread dog,cat;        //�߳���Ŀ�����ĳ�Ա
    House() {
        dog=new Thread(this);  //��ǰHouse������Ϊ�̵߳�Ŀ�����
        cat=new Thread(this);
    }
    public void setWater(int w) {
        waterAmount = w;
    }
    public void run() {
        while(true) {
            Thread t=Thread.currentThread();
            if(t==dog) {
                System.out.println("狗狗喝水ˮ") ;
                waterAmount=waterAmount-2;  //���ȵĶ�
            }
            else if(t==cat){
                System.out.println("猫猫喝水ˮ") ;
                waterAmount=waterAmount-1;  //è�ȵ���
            }
            System.out.println(" 剩 "+waterAmount);
            try{  Thread.sleep(2000);  //���ʱ��
            }
            catch(InterruptedException e){}
            if(waterAmount<=0) {
                return;
            }
        }
    }
}

